//
//  ViewController.m
//  UI10-CustomTableViewCell
//
//  Created by 韩旭 on 16/7/27.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "ViewController.h"
#import "HX_CustomTableCell.h"
#import "NewsObject.h"
#define WIDETH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height
#define COLORAUTO [UIColor colorWithRed:(arc4random()%256/255.0) green:(arc4random()%256/255.0) blue:(arc4random()%256/255.0) alpha:1.0]
#define kWidth [UIScreen mainScreen].bounds.size.width
#define kHeight [UIScreen mainScreen].bounds.size.height
@interface ViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *arrSource;
@end

@implementation ViewController
//- (NSMutableArray *)arrSource {
//    if (!_arrSource) {
//        self.arrSource = [NSMutableArray array];
//    }
//    return _arrSource;
//}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.arrSource = [NSMutableArray array];
    self.view.backgroundColor = [UIColor redColor];
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kHeight) style:0];
    
//    数据的传递依赖model，传对象存对象取对象
    NewsObject *newsObject = [[NewsObject alloc] initWithImage:@"1_141105193631_1.jpg" newTitle:@"张何&蔚 VS SB" Descripition:@"大连暴雨劈死你" newNumber:@"1.6万人"];
    self.arrSource = [NSMutableArray arrayWithObjects:newsObject, newsObject, newsObject, nil];
//    NSArray *arr = @[@"唐益梦", @"张合尉", @"高雅馨", @"符淋淋", @"孙遥", @"李毅然", @"于瀚", @"沙长健", @"卢思彤", @"徐昊", @"曹冠雄", @"陈丹明", @"罗浩", @"肖扬", @"王道林", @"宫雪", @"李成", @"冀永金", @"姜浩", @"罗鹏飞", @"李昊林", @"郭宝", @"马峰", @"刘坦奇", @"殷明静", @"邓凯", @"徐康", @"王鍠", @"韩旭", @"杨睿", @"张信宝", @"姜程程", @"包铭礼", @"杜江", @"苗钧豪"];
//    _arrSource = [arr mutableCopy];e
    _tableView.backgroundColor = [UIColor whiteColor];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
//    使用自定义cell需要修改
//    1. 注册对应的cell的类型
//    2. 重用池取出cell的类型
//    3. 自定义cell继承于UITableViewCell
    [_tableView registerClass:[HX_CustomTableCell class] forCellReuseIdentifier:@"cell"];
//    多种cell混合使用
//    注册cell 时 注意重用标识不能一样
    [_tableView registerClass:[HX_CustomTableCell class] forCellReuseIdentifier:@"cellsd"];
    self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:animated];
    [_tableView setEditing:editing animated:animated];
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 1;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _arrSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//    static NSString *ID = @"cell";
//    HX_CustomTableCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
//    if (!cell) {
//        cell = [[HX_CustomTableCell alloc] initWithStyle:3 reuseIdentifier:ID];
//    }
    
//    多种cell同时使用时，可以根据下标决定样式
//    注意：判断情况一定要判断完整
    
    if (indexPath.row == 1) {
        HX_CustomTableCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellsd"];
        return cell;
    } else {
        //    cell.textLabel.text = _arrSource[indexPath.row];
        HX_CustomTableCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
        //    给自定义属兔赋值
        //    如果图片后缀是jpg加上jpg png不用
        cell.newsObject = self.arrSource[indexPath.row];
        //    cell.imageTitle.image = [UIImage imageNamed:@"1_141105193631_1.jpg"];
        //    cell.lable.text = @"张何&蔚 VS SB";
        //    cell.lable.textAlignment = 1;
        //    cell.lableDetail.text = @"大连暴雨劈死你";
        //    cell.lableSmall.text = @"1.6万人";
        return cell;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 200;
}
@end
